package com.hs.spring_001.controller;

import com.github.pagehelper.PageInfo;
import com.hs.spring_001.entry.Users;
import com.hs.spring_001.mapper.UserMapper;
import com.hs.spring_001.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    UserService service;

    @GetMapping
    public List<Users> findAll(){
        return service.fidnAll();
    }

    @GetMapping("/page/{pageNum}/{pageSize}")
    public HashMap<String,Object> findByPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        PageInfo<Users> byPage = service.findByPage(pageNum, pageSize);
        HashMap<String,Object> map = new HashMap<>();
        map.put("list",byPage.getList());
        map.put("total",byPage.getTotal());
        return map;
    }
}
